package com.kingyea.mobilepolice.apimanage.providerservicehost.controller;

import com.kingyea.mobilepolice.apimanage.providerservicehost.bean.ProviderServiceHost;
import com.kingyea.mobilepolice.apimanage.providerservicehost.service.ProviderServiceHostService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.UUID;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description ProviderServiceHost 控制层
 * @date Created in 2018-05-19 16:13:25
 */
@RequestMapping(value = "/providerServiceHost")
@RestController
public class ProviderServiceHostController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ProviderServiceHostController.class);

    @Autowired
    private ProviderServiceHostService providerServiceHostService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public Object list() throws Exception {
        return providerServiceHostService.list(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param hostSerialNo
     * @return
     */
    @RequestMapping(value = "/{hostSerialNo}", method = RequestMethod.GET)
    public Object detail(@PathVariable String hostSerialNo) throws Exception {
        return providerServiceHostService.getById(hostSerialNo);
    }

    @RequestMapping(value = "/searchByCondition", method = RequestMethod.POST)
    public Object searchByCondition(@RequestBody Map<String, Object> map) throws Exception {
        return providerServiceHostService.searchByCondition(map);
    }

    /**
     * 创建
     *
     * @param providerServiceHost
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public Object create(@RequestBody ProviderServiceHost providerServiceHost) throws Exception {
        providerServiceHost.setHostSerialNo(UUID.randomUUID().toString());
        return providerServiceHostService.save(providerServiceHost);
    }

    /**
     * 更新
     *
     * @param providerServiceHost
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public Object update(@RequestBody ProviderServiceHost providerServiceHost) throws Exception {
        return providerServiceHostService.update(providerServiceHost);
    }

    /**
     * 删除
     *
     * @param hostSerialNo
     * @return
     */
    @RequestMapping(value = "/{hostSerialNo}", method = RequestMethod.DELETE)
    public Object delete(@PathVariable String hostSerialNo) throws Exception {
        return providerServiceHostService.deleteById(hostSerialNo);
    }

}
